package com.authine.cloudpivot.ext.dto;

import com.authine.cloudpivot.ext.enums.order.DeliverEnum;
import com.authine.mvp.app.launcher.domain.SelectorFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Created by Kris on 2019/3/25
 */
@Data
@Schema(description = "DeliverVO")
@ApiModel("发货单查询")
public class DeliverVO {
    @Schema(description = "发货物料", hidden = true)
    private List<MaterialVO> materialVOS;
    @Schema(description = "发货单ID")
    private String id;
    @Schema(description = "客户id")
    private SelectorFormat customerId;
    @Schema(description = "供应商id")
    private SelectorFormat vendorId;
    @Schema(description = "用户id")
    private SelectorFormat memberId; // 用户Id
    @Schema(description = "发货通知单id")
    private String deliverNoticeId; //发货通知单id
    @Schema(description = "状态")
    private DeliverEnum deliverStatus;
    @Schema(description = "物流名称")
    private String waybill; //物流名称
    @Schema(description = "物流单号")
    private String logistics;  //物流单号
    @Schema(description = "开始时间", pattern = "yyyy-MM-dd HH:mm:ss")
    private String startTime;
    @Schema(description = "结束时间", pattern = "yyyy-MM-dd HH:mm:ss")
    private String endTime;
    @Schema(description = "客户组织名称")
    private String customerName;
    @Schema(description = "供应商组织名称")
    private String vendorName;

    public static Map<String, Object> voToEntity(DeliverVO deliverVO) {
        Map<String, Object> result = new HashMap<>();
        result.put("customer_id", deliverVO.getCustomerId());
        result.put("customer_name", Objects.isNull(deliverVO.getCustomerId()) ? null : deliverVO.getCustomerId().getName());
        result.put("vendor_id", deliverVO.getVendorId());
        result.put("vendor_name", Objects.isNull(deliverVO.getVendorId()) ? null : deliverVO.getVendorId().getName());
        result.put("member_id", deliverVO.getMemberId());
        result.put("deliver_notice_id", deliverVO.getDeliverNoticeId());
        result.put("deliver_status", deliverVO.getDeliverStatus().name());
        result.put("waybill", deliverVO.getWaybill());
        result.put("logistics", deliverVO.getLogistics());
        return result;
    }
}
